<template>
  <div>
    <FormPanel ref="from" :list="formList" :formType="type" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />

    <FilterTable ref="table" :height="'auto'" :columns="columns" :dataSource="tableList" :onColumnsChange="columns => (this.columns = columns)" :isSelectColumn="false"></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">返回</el-button>
    </div>
  </div>
</template>
<script>
import { queryDailyByDate } from '@/api/omSale/DealerDaily/Dealerquiry';
import { dictionary } from '@/utils/dictMixin';

export default {
  name: 'addModel',
  props: ['type', 'rowData'], // 上个页面带入的值
  data() {
    this.saveData = null;
    this.BaseTable = null;
    return {
      formList: this.createdFrom(),
      columns: this.createdTable(),
      tableList: [],
      fromData: {}
    };
  },
  created() {
    this.init();
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  mixins: [dictionary],
  methods: {
    async init() {
      console.log(this.rowData, '你是啥');
      const res = await queryDailyByDate({ applyDate: this.rowData.applyDate, ownerCode: this.rowData.ownerCode });
      if (res.resultCode == 200) {
        this.formList.map(x => {
          if (x.fieldName == 'applyDate') {
            x.initialValue = res.data.ttVsDailyDTOs ? res.data.ttVsDailyDTOs[0].applyDate : '';
          } else {
            x.initialValue = res.data[x.fieldName];
          }
        });

        this.tableList = res.data.modelCacheVOList ? JSON.parse(JSON.stringify(res.data.modelCacheVOList)) : res.data.ttVsDailyDTOs || [];
      }
    },
    changeHandle(val) {},
    closeDrawer() {
      this.$emit('close', false);
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'ownerCode',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '事业部',
          fieldName: 'deptName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '办事处',
          fieldName: 'officeName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '区域经理',
          fieldName: 'regionalManager',
          placeholder: ''
        },
        {
          type: 'DATE',
          label: '上报日期',
          fieldName: 'applyDate',
          dateType: 'exactdate',
          placeholder: ''
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '车型',
          dataIndex: 'modelName'
        },
        {
          title: '展厅访问',
          dataIndex: 'exhibitionHallVisit'
        },
        {
          title: '来电/网络',
          dataIndex: 'callOrNetwork'
        },
        {
          title: '外拓',
          dataIndex: 'promoting'
        },
        {
          title: '留档',
          dataIndex: 'maintained'
        },
        {
          title: '试驾',
          dataIndex: 'testDrive'
        },
        {
          title: '新增订单',
          dataIndex: 'newOrder'
        },
        {
          title: '累计未交',
          dataIndex: 'accumulatedUnpaid'
        },
        {
          title: '开票',
          dataIndex: 'billCount'
        }
      ];
    }
  }
};
</script>
